
using UnityEngine;
using UnityEngine.Events;

public class CollisionDetector : MonoBehaviour
{
    [SerializeField]
    private string _colliderScript;

    [SerializeField]
    private UnityEvent _collisionEntered;

    [SerializeField]
    private UnityEvent _collisionExit;

    // 当其他物体进入触发器时调用的方法
    private void OnTriggerEnter2D(Collider2D other) {
        if (other.gameObject.GetComponent(_colliderScript))
        {
            _collisionEntered?.Invoke();
        }
    }

    // 当其他物体离开触发器时调用的方法
    private void OnTriggerExit2D(Collider2D other){
        if (other.gameObject.GetComponent(_colliderScript))
        {
            _collisionExit?.Invoke();
        }
    }
}